

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>文件布局 &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" />

  
  
    <link rel="shortcut icon" href="../../_static/favicon.ico"/>
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex/" />
    <link rel="search" title="Search" href="../../search/" />
    <link rel="next" title="CephFS Distributed Metadata Cache" href="../mdcache/" />
    <link rel="prev" title="MDS Journaling" href="../mds-journaling/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../">Ceph 文件系统</a> &raquo;</li>
        
      <li>文件布局</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../_sources/cephfs/file-layouts.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../">
          

          
            
            <img src="../../_static/logo.png" class="logo" alt="Logo"/>
          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../start/intro/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../cephadm/">Cephadm</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../rados/">Ceph 存储集群</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../">Ceph 文件系统</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../#cephfs">CephFS 入门</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id4">管理</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id5">挂载 CephFS</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../#id6">CephFS 内幕</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../mds-states/"> MDS 的各种状态</a></li>
<li class="toctree-l3"><a class="reference internal" href="../posix/"> POSIX 兼容性</a></li>
<li class="toctree-l3"><a class="reference internal" href="../mds-journaling/"> MDS 日志记录</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#"> 文件布局</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#id2">布局字段</a></li>
<li class="toctree-l4"><a class="reference internal" href="#getfattr">用 <code class="docutils literal notranslate"><span class="pre">getfattr</span></code> 读取布局</a></li>
<li class="toctree-l4"><a class="reference internal" href="#setfattr">用 <code class="docutils literal notranslate"><span class="pre">setfattr</span></code> 设置布局</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id3">清除布局</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id4">布局的继承</a></li>
<li class="toctree-l4"><a class="reference internal" href="#adding-data-pool-to-file-system">把数据存储池加入文件系统</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../mdcache/"> 分布式元数据缓存</a></li>
<li class="toctree-l3"><a class="reference internal" href="../dynamic-metadata-management/"> CephFS 内的动态元数据管理</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cephfs-io-path/"> CephFS IO 路径</a></li>
<li class="toctree-l3"><a class="reference internal" href="../lazyio/"> LazyIO</a></li>
<li class="toctree-l3"><a class="reference internal" href="../dirfrags/"> 目录分片的配置</a></li>
<li class="toctree-l3"><a class="reference internal" href="../multimds/"> 多活 MDS 的配置</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../#id7">故障排除和灾难恢复</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id9">更多细节</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../rbd/">Ceph 块设备</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../radosgw/">Ceph 对象网关</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <div class="section" id="file-layouts">
<span id="id1"></span><h1>文件布局<a class="headerlink" href="#file-layouts" title="Permalink to this headline">¶</a></h1>
<p>文件布局可控制如何把文件内容映射到各 Ceph RADOS 对象，你可以用<em>虚拟扩展属性</em>或 xattrs 来读、写某一文件的布局。</p>
<p>布局 xattrs 的名字取决于此文件是常规文件还是目录，常规文件的布局 xattrs 叫作 <code class="docutils literal notranslate"><span class="pre">ceph.file.layout</span></code> 、目录的布局 xattrs 叫作
<code class="docutils literal notranslate"><span class="pre">ceph.dir.layout</span></code> 。因此后续实例中若用的是
<code class="docutils literal notranslate"><span class="pre">ceph.file.layout</span></code> ，处理目录时就要替换为 <code class="docutils literal notranslate"><span class="pre">dir</span></code> 。</p>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>你的 Linux 发行版也许默认没提供操作 xattrs 的命令，所需软件包通常是 <code class="docutils literal notranslate"><span class="pre">attr</span></code> 。</p>
</div>
<div class="section" id="id2">
<h2>布局字段<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h2>
<dl class="simple">
<dt>pool</dt><dd><p>字符串，可指定 ID 或名字，其字符必须出自 [a-zA-Z0-9_-.] 集合。
它是文件的数据对象所在的 RADOS 存储池。</p>
</dd>
<dt>pool_namespace</dt><dd><p>字符串，其字符必须出自 [a-zA-Z0-9_-.] 集合。在数据存储池内，
对象应该写入哪个 RADOS 命名空间，默认为空（即默认命名空间）。</p>
</dd>
<dt>stripe_unit</dt><dd><p>字节数、整数。一个文件的数据块按照此尺寸（字节）像 RAID 0 一样分布。
一文件所有条带单元的尺寸一样，最后一个条带单元通常不完整——
即它包含文件末尾的数据、还有数据末端到固定条带单元尺寸之间的未使用“空间”。</p>
</dd>
<dt>stripe_count</dt><dd><p>整数。组成 RAID 0 “条带”数据的连续条带单元数量。</p>
</dd>
<dt>object_size</dt><dd><p>整数个字节。文件数据按此尺寸分块为 RADOS 对象。</p>
</dd>
</dl>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>RADOS 会确保对象的尺寸是个可配置的限量：如果你自行增大 CephFS 对象尺寸，
超过了那个限量，那么写入可能不会成功。
对应的 OSD 选项是 <code class="docutils literal notranslate"><span class="pre">osd_max_object_size</span></code> ，默认值是 128MB 。
RADOS 对象过于大可能会影响集群的平稳运行，所以不建议对象尺寸限量超过默认值。</p>
</div>
</div>
<div class="section" id="getfattr">
<h2>用 <code class="docutils literal notranslate"><span class="pre">getfattr</span></code> 读取布局<a class="headerlink" href="#getfattr" title="Permalink to this headline">¶</a></h2>
<p>读出的布局信息表示为单个字符串：</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ touch file
$ getfattr -n ceph.file.layout file
<span class="c1"># file: file</span>
ceph.file.layout<span class="o">=</span><span class="s2">&quot;stripe_unit=4194304 stripe_count=1 object_size=4194304 pool=cephfs_data&quot;</span>
</pre></div>
</div>
<p>读取单个布局字段：</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ getfattr -n ceph.file.layout.pool file
<span class="c1"># file: file</span>
ceph.file.layout.pool<span class="o">=</span><span class="s2">&quot;cephfs_data&quot;</span>
$ getfattr -n ceph.file.layout.stripe_unit file
<span class="c1"># file: file</span>
ceph.file.layout.stripe_unit<span class="o">=</span><span class="s2">&quot;4194304&quot;</span>
$ getfattr -n ceph.file.layout.stripe_count file
<span class="c1"># file: file</span>
ceph.file.layout.stripe_count<span class="o">=</span><span class="s2">&quot;1&quot;</span>
$ getfattr -n ceph.file.layout.object_size file
<span class="c1"># file: file</span>
ceph.file.layout.object_size<span class="o">=</span><span class="s2">&quot;4194304&quot;</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>读取布局时，存储池通常是以名字标识的。
然而在极少数情况下，如存储池刚创建时，可能会输出 ID 。</p>
</div>
<p>目录只有经过定制才会有显式的布局，如果从没更改过，那么读取其布局时就会失败：这表明它会继承父目录的显式布局设置。</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ mkdir dir
$ getfattr -n ceph.dir.layout dir
dir: ceph.dir.layout: No such attribute
$ setfattr -n ceph.dir.layout.stripe_count -v <span class="m">2</span> dir
$ getfattr -n ceph.dir.layout dir
<span class="c1"># file: dir</span>
ceph.dir.layout<span class="o">=</span><span class="s2">&quot;stripe_unit=4194304 stripe_count=2 object_size=4194304 pool=cephfs_data&quot;</span>
</pre></div>
</div>
</div>
<div class="section" id="setfattr">
<h2>用 <code class="docutils literal notranslate"><span class="pre">setfattr</span></code> 设置布局<a class="headerlink" href="#setfattr" title="Permalink to this headline">¶</a></h2>
<p>布局字段可用 <code class="docutils literal notranslate"><span class="pre">setfattr</span></code> 修改：</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ ceph osd lspools
<span class="m">0</span> rbd
<span class="m">1</span> cephfs_data
<span class="m">2</span> cephfs_metadata

$ setfattr -n ceph.file.layout.stripe_unit -v <span class="m">1048576</span> file2
$ setfattr -n ceph.file.layout.stripe_count -v <span class="m">8</span> file2
$ setfattr -n ceph.file.layout.object_size -v <span class="m">10485760</span> file2
$ setfattr -n ceph.file.layout.pool -v <span class="m">1</span> file2  <span class="c1"># Setting pool by ID</span>
$ setfattr -n ceph.file.layout.pool -v cephfs_data file2  <span class="c1"># Setting pool by name</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>用 <code class="docutils literal notranslate"><span class="pre">setfattr</span></code> 命令修改文件的布局字段时，此文件必须是空的，否则会报错。</p>
</div>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="c1"># 创建空文件</span>
$ touch file1
<span class="c1"># 可如愿修改布局字段</span>
$ setfattr -n ceph.file.layout.stripe_count -v <span class="m">3</span> file1

<span class="c1"># 向文件写入些东西</span>
$ <span class="nb">echo</span> <span class="s2">&quot;hello world&quot;</span> &gt; file1
$ setfattr -n ceph.file.layout.stripe_count -v <span class="m">4</span> file1
setfattr: file1: Directory not empty
</pre></div>
</div>
</div>
<div class="section" id="id3">
<h2>清除布局<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h2>
<p>如果你想删除某一目录的布局，还继承上级的布局，可以这样：</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>setfattr -x ceph.dir.layout mydir
</pre></div>
</div>
<p>类似地，如果你已经设置了 <code class="docutils literal notranslate"><span class="pre">pool_namespace</span></code> 属性，又想让布局改回默认命名空间：</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="c1"># 创建个目录，并给它设置命名空间</span>
mkdir mydir
setfattr -n ceph.dir.layout.pool_namespace -v foons mydir
getfattr -n ceph.dir.layout mydir
ceph.dir.layout<span class="o">=</span><span class="s2">&quot;stripe_unit=4194304 stripe_count=1 object_size=4194304 pool=cephfs_data_a pool_namespace=foons&quot;</span>

<span class="c1"># 清除目录布局的命名空间</span>
setfattr -x ceph.dir.layout.pool_namespace mydir
getfattr -n ceph.dir.layout mydir
ceph.dir.layout<span class="o">=</span><span class="s2">&quot;stripe_unit=4194304 stripe_count=1 object_size=4194304 pool=cephfs_data_a&quot;</span>
</pre></div>
</div>
</div>
<div class="section" id="id4">
<h2>布局的继承<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h2>
<p>文件会在创建时继承其父目录的布局，然而之后对父目录布局的更改不会影响其子孙。</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ getfattr -n ceph.dir.layout dir
<span class="c1"># file: dir</span>
ceph.dir.layout<span class="o">=</span><span class="s2">&quot;stripe_unit=4194304 stripe_count=2 object_size=4194304 pool=cephfs_data&quot;</span>

<span class="c1"># 证实 file1 继承了其父的布局</span>
$ touch dir/file1
$ getfattr -n ceph.file.layout dir/file1
<span class="c1"># file: dir/file1</span>
ceph.file.layout<span class="o">=</span><span class="s2">&quot;stripe_unit=4194304 stripe_count=2 object_size=4194304 pool=cephfs_data&quot;</span>

<span class="c1"># 现在更改目录布局，然后再创建第二个文件</span>
$ setfattr -n ceph.dir.layout.stripe_count -v <span class="m">4</span> dir
$ touch dir/file2

<span class="c1"># 证实 file1 的布局未变</span>
$ getfattr -n ceph.file.layout dir/file1
<span class="c1"># file: dir/file1</span>
ceph.file.layout<span class="o">=</span><span class="s2">&quot;stripe_unit=4194304 stripe_count=2 object_size=4194304 pool=cephfs_data&quot;</span>

<span class="c1"># 但 file2 继承了父目录的新布局</span>
$ getfattr -n ceph.file.layout dir/file2
<span class="c1"># file: dir/file2</span>
ceph.file.layout<span class="o">=</span><span class="s2">&quot;stripe_unit=4194304 stripe_count=4 object_size=4194304 pool=cephfs_data&quot;</span>
</pre></div>
</div>
<p>如果中层目录没有设置布局，那么内层目录中创建的文件也会继承此目录的布局：</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ getfattr -n ceph.dir.layout dir
<span class="c1"># file: dir</span>
ceph.dir.layout<span class="o">=</span><span class="s2">&quot;stripe_unit=4194304 stripe_count=4 object_size=4194304 pool=cephfs_data&quot;</span>
$ mkdir dir/childdir
$ getfattr -n ceph.dir.layout dir/childdir
dir/childdir: ceph.dir.layout: No such attribute
$ touch dir/childdir/grandchild
$ getfattr -n ceph.file.layout dir/childdir/grandchild
<span class="c1"># file: dir/childdir/grandchild</span>
ceph.file.layout<span class="o">=</span><span class="s2">&quot;stripe_unit=4194304 stripe_count=4 object_size=4194304 pool=cephfs_data&quot;</span>
</pre></div>
</div>
</div>
<div class="section" id="adding-data-pool-to-file-system">
<span id="id5"></span><h2>把数据存储池加入文件系统<a class="headerlink" href="#adding-data-pool-to-file-system" title="Permalink to this headline">¶</a></h2>
<p>要通过 CephFS 使用一个存储池，你必须把它加入元数据服务器。</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ ceph fs add_data_pool cephfs cephfs_data_ssd
$ ceph fs ls  <span class="c1"># Pool should now show up</span>
.... data pools: <span class="o">[</span>cephfs_data cephfs_data_ssd <span class="o">]</span>
</pre></div>
</div>
<p>确保你的 cephx 密钥允许客户端访问这个新存储池。</p>
<p>然后就能在 CephFS 内更新一个目录的布局了，以使用刚加上的存储池：</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$ mkdir /mnt/cephfs/myssddir
$ setfattr -n ceph.dir.layout.pool -v cephfs_data_ssd /mnt/cephfs/myssddir
</pre></div>
</div>
<p>此后，在那个目录内新创建的文件都会继承它的布局、
并把它们的数据放入你新加的存储池。</p>
<p>你也许注意到了，主数据存储池（传递给 <code class="docutils literal notranslate"><span class="pre">fs</span> <span class="pre">new</span></code> 的那个）内的对象计数仍在继续增加，即使创建的文件位于你后加的存储池内。这很正常：文件的数据存储于由布局指定的存储池内，
但是所有文件的元数据还都存储在主数据存储池内，数量很小。</p>
</div>
</div>



           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="../mdcache/" class="btn btn-neutral float-right" title="CephFS Distributed Metadata Cache" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="../mds-journaling/" class="btn btn-neutral float-left" title="MDS Journaling" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).

    </p>
  </div> 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>